<?php
/**
 * Created by Jasmine.
 * Date: 2016/9/26
 * description:
 * Address: 浙江宣逸网络科技有限公司
 */

namespace Wap\Controller;


use Common\Model\EditorModel;
use Common\Model\UserModel;
use Common\Model\UtilsModel;
use Common\Model\WeixinModel;
use Wap\BaseController;

class EditorController extends BaseController
{

    //评价列表
    public function evaluateList(){
        $uid = session('uid') + 0;
        UtilsModel::checkLogin();
        $userRole = UserModel::getUserRole($uid);
        if($userRole == SYSTEM_ROLE_BUSINESS_MANAGER){
            $list = EditorModel::evaluateList($uid);
            $this->smarty->assign('list',$list);
            $this->smarty->assign("title", "商务评价列表");
            $this->smarty->display("Editor/evaluateList.html");
        }
    }

    //评价页面
    public function evaluate()
    {
        $uid = session('uid') + 0;
        UtilsModel::checkLogin();
        $userRole = UserModel::getUserRole($uid);
        if($userRole == SYSTEM_ROLE_BUSINESS_MANAGER){
            $id = I('get.id',0,'intval');
            $data = EditorModel::evaluatePage($id);
            $this->smarty->assign('data',$data);
            $this->smarty->assign("title", "商务评价");
            $this->smarty->display("Editor/evaluate.html");
        }
    }

    //新增评价
    public function addEvaluate()
    {
        $uid = session('uid') + 0;
        $id = I('get.id',0,'intval');
        $attitude = I('get.score', 0, 'intval');
        $speed = I('get.hj', 0, 'intval');
        $environment = I('get.service', 0, 'intval');
        $content = htmlspecialchars_decode(I('get.content'));

        $data = EditorModel::businessManagerEvaluate($uid,$id,$attitude,$speed,$environment,$content);
        $this->ajaxReturn($data);

    }

    //数据统计
    public function statisticData()
    {
        $uid = session('uid') + 0;
        UtilsModel::checkLogin();
        $userRole = UserModel::getUserRole($uid);
        if($userRole == SYSTEM_ROLE_EDITOR){
            $dayData = EditorModel::getDayData();
            $this->smarty->assign('data', $dayData);

            $type = EditorModel::getType();
            $this->smarty->assign("type", $type);

            $this->smarty->assign("time", strtotime("-1 day"));
            $this->smarty->assign("date", EditorModel::DATE_YESTERDAY);
            $this->smarty->assign("title", "小编达人数据统计");
            $this->smarty->display("Editor/statisticData.html");
        }
    }

    //统计数据展示
    public function getData()
    {
        $uid = session('uid') + 0;
        $userRole = UserModel::getUserRole($uid);
        if($userRole == SYSTEM_ROLE_EDITOR){
        $data=null;
        $date = I('get.date', 1, 'intval');
        if ($date == EditorModel::DATE_YESTERDAY) {
            $data = EditorModel::getDayData();
            $this->smarty->assign("time", strtotime("-1 day"));
            $this->smarty->assign("date", EditorModel::DATE_YESTERDAY);
        } else if ($date == EditorModel::DATE_LAST_WEEK) {
            $data = EditorModel::getWeekData();
            $time = UtilsModel::getTimeWeek(time());
            $this->smarty->assign("time", $time);
            $this->smarty->assign("date", EditorModel::DATE_LAST_WEEK);
        } else if ($date == EditorModel::DATE_LAST_MONTH){
            $data = EditorModel::getMonData();
            $this->smarty->assign("time", strtotime("-1 month"));
            $this->smarty->assign("date", EditorModel::DATE_LAST_MONTH);
        }

        $this->smarty->assign('data', $data);
        $type = EditorModel::getType();
        $this->smarty->assign("type", $type);

        $dataHtml = $this->smarty->fetch("Editor/data.html");
        $this->ajaxReturn(array('dataHtml' => $dataHtml));
        }
    }

    //小编录入
    public function weiXinFriendWrite(){
        $uid = session('uid') + 0;
        UtilsModel::checkLogin();
        $userRole = UserModel::getUserRole($uid);
        if($userRole == SYSTEM_ROLE_EDITOR) {
            $data = EditorModel::getEditorWriteData($uid);
            $this->smarty->assign('data',$data);
            $this->smarty->assign("time", time());
            $this->smarty->assign('title', "小编录入");
            $this->smarty->display("Editor/write.html");
        }
    }

    //保存录入信息
    public function saveWriteData(){
        $uid = session('uid') + 0;
        $friendNum = I('get.friendNum',0,'intval');
        $groupFriend = I('get.groupFriendNum',0,'intval');
        $newFriendNum = I('get.newFriendNum',0,'intval');
        $data = EditorModel::saveEditorWriteData($uid,$friendNum,$groupFriend,$newFriendNum);
        $this->ajaxReturn($data);
    }

    //数据录入成功
    public function saveSuccess(){
        $this->smarty->assign('title',"录入成功");
        $this->smarty->display("Editor/writeSuccess.html");
    }
}